package com.wen.common.utils;

import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.crypto.hash.SimpleHash;

/**
 * @author Devin QQ:1441289544
 * @description
 * @create 2022-02-14 15:50:55
 */
public class Md5Util {

    //加密方式
    private static final String ALGORITHM_NAME = "MD5";

    //默认盐值
    private static final String DEFAULT_SALT = "devinsite";

    //默认散列次数
    private static final int DEFAULT_ITERATIONS = 998;


    /**
     * 返回默认盐值
     */
    public static String getDefaultSalt() {
        return DEFAULT_SALT;
    }

    /**
     * 返回加密次数
     */
    public static int getDefaultCount() {
        return DEFAULT_ITERATIONS;
    }

    /**
     * MD5加密
     */
    public static String md5Str(String source) {
        return new Md5Hash(source, DEFAULT_SALT, DEFAULT_ITERATIONS).toString();
    }

    /**
     * MD5加密
     */
    public static String md5Str(String source, String salt) {
        return new Md5Hash(source, salt, DEFAULT_ITERATIONS).toString();
    }

    /**
     * MD5加密
     */
    public static String md5Str(String source, String salt, int iterations) {
        return new Md5Hash(source, salt, iterations).toString();
    }
}
